﻿@{
    Layout = "~/Views/Shared/_LoginRegLayout.cshtml";
    byte[] vcdata = ViewBag.VCodeImg;
}
@model Yyyg.WebUI.Models.UserLoginVM

@section head{
    <script src="~/Lib/jsencrypt.min.js"></script>
    <script src="~/Scripts/jquery.form.js"></script>
    <link href="~/Content/loginpage.css" rel="stylesheet" />
    @*<script src="~/Scripts/src/userlogin.js?v=202105161725"></script>*@
}

@using (Html.BeginForm("Login", "UserLogin", FormMethod.Post, new { id = "login-form", @class = "login-block" }))
{
    <h5>登录<small>@Html.ActionLink("前往注册", "Reg", "UserReg")<span style="color:#ccc"> | </span><a style="color:orange" href="#">忘记密码？</a></small></h5>
    <div class="content">
        <div class="input-ls">
            <div>
                @Html.TextBoxFor(s => s.Account, new { id = "account", name = "Account", autocomplete = "off", placeholder = "输入注册手机号或绑定邮箱" })
                @*<input type="text" name="Account" autocomplete="off" placeholder="请使用注册邮箱或手机号" />*@
                <span class="input-user iconfont icon-mobile-phone"></span>
            </div>
            <div>
                @Html.ValidationMessageFor(s => s.Account, null, new { style = "color:red;font-size:0.8rem;" })
            </div>
        </div>
        <div class="input-ls">
            <div>
                @* 实际提交的密码段 *@
                <input style="display:none" type="password" id="encrypt-pwd" name="Pwd" value="" />
                <input type="password" id="pwd" maxlength="26" placeholder="输入密码" autocomplete="off" value="" />
                <span class="input-user iconfont icon-lock"></span>
            </div>
            <div>
                @Html.ValidationMessageFor(s => s.Pwd, null, new { style = "color:red;font-size:0.8rem;" })
            </div>
        </div>
        <div class="input-ls">
            <div>
                <input type="text" name="VerifyCode" id="verifyCode" autocomplete="off" placeholder="输入图形验证码" />
                <img title="点击刷新" id="vcimg" src="data:image/png;base64,@Convert.ToBase64String(vcdata)" style="display:inline-block;height:40px;position:absolute;bottom:0px;" />
            </div>
            <div>
                @Html.ValidationMessageFor(s => s.VerifyCode, null, new { style = "color:red;font-size:0.8rem;" })
            </div>
        </div>
        <div class="input-ls">
            <div>
                @Html.CheckBoxFor(s => s.Remember, new { id = "remember" })
                <span class="blkfont">七天免登录</span>
            </div>
        </div>
        <div class="input-btn">
            <button class="loginbtn btn-big ajax-post" type="submit" style="outline:none;" target-form="form-user">登 陆</button>
        </div>
    </div>
}
<i id="rsa-pubkey" style="display:none">@RSASingle.PubKey_PEM_PKCS1</i>
<script>
    $(function () {

        $("#login-form").submit(function (e) {
            var vc = $("#verifyCode").val();
            if (!vc || vc.length == 0) {
                e.preventDefault();
                window.alert("必须输入验证码!");
                return;
            }
            let pwd = $("#pwd").val();
            //获取公钥
            let pubkey = $("#rsa-pubkey").text();
            let ecrypt = new JSEncrypt();
            //设置公钥
            ecrypt.setPublicKey(pubkey);
            //获取密文
            let ecryptText = ecrypt.encrypt(pwd);
            $("#encrypt-pwd").val(ecryptText);
        })

        $("#vcimg").click(function () {
            $.get("ReloadverifyCode", null, function (data) {
                $("#vcimg").attr("src", `data:image/png;base64,${data}`);
            }, "text");
        })
    });
</script>